import { AppDispatch } from '..'
import http from '../../utils/request'
import { ChannelAction } from '../reducer/channel'

// 获取频道列表
export const getChannelList = () => {
  return async (dispatch: AppDispatch) => {
    // 发送请求获取数据
    const res = await http.get('/v1_0/channels')
    console.log(res)
    // 数据获取成功调用 dispatch 存到仓库中
    dispatch({ type: 'channel/saveList', payload: res.data.channels })
  }
}

// 更新激活状态的频道
export const changeActive = (index: number): ChannelAction => {
  return { type: 'channel/setActive', payload: index }
}
